/**
 * @copyright Copyright (c) 2025 
 * CSG Digital Grid Technology (Guangdong) Co., Ltd.
 * @author klg
 * @brief 通用功能头文件，包含常用工具函数和类型定义
 */
#ifndef __COMMON_H__
#define __COMMON_H__

/* base */
#include <pthread.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>

#include <sys/stat.h>
#include <sys/types.h>

#include "version.h"

typedef int BOOL;
#define true 1
#define false 0

#define DEVICE_NAME "electricity gateway"
#define APP_NAME _APP_NAME
#define SOFTWARE_VERSION _APP_VERSION
#define COMPATIBLE_VERSION "OS01.018"
#define HARDWARE_VERSION "1.0"

#define CONFIG_PATH_JSON "egw_config.json"

int is_app_running(void);
void set_app_running(int running);

int file_exist(const char *file_dir);
int creat_dir(const char *path);

char *read_file(const char *filename);
int write_file(const char *filename, const char *buf);

void sleep_ms(unsigned int ms);
void sleep_s(unsigned int s);

const char *get_compiled_date_yyyy_mm_dd(void);
const char *get_compiled_date_yyyymmdd(void);

long long get_system_time_ms(void);

int system_minute(void);

int char_to_int(char *ch);
void int_to_char(int value, char *ch);
float char_to_float(char *ch);
int str_is_digit(char *p_str);
int strcmpnum(char *s, char *t);

void split(char *src, const char *separator, char **dest, int *num);

void split_dev_string(const char *input, char *model, char *guid);

off_t get_file_size(const char *filepath);

off_t get_directory_size(const char *dirpath);

off_t get_remaining_space_size(const char *dirpath);

#endif
